/**
 * @author 李楠君
 * 短信群发
 */
package com.safe.ocs.controls;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.safe.ocs.forms.SendForm;
import com.safe.ocs.services.SendMsg;

public class SendMessage extends DispatchAction {
	
	
	/**
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 * 查询人员信息
	 */
	public ActionForward findPerson(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		SendForm sform = (SendForm) form;
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String telNo = sform.getChk_telNo();
		String name = sform.getTxt_name();
		String result = new SendMsg().findPerson(telNo,name);
		out.println(result);
		return null;
	}
	
	/**
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 
	 * @throws Exception
	 * 短信群发
	 */
	public ActionForward sendMessage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setContentType("text/html;charset=utf-8");
		SendForm sform = (SendForm)form;
		PrintWriter out = response.getWriter();
		String telNo = sform.getChk_telNo();	
		String msgContent = sform.getTxt_content();
		if(telNo!=null&&!"".equals(telNo)&&msgContent!=null&&!"".equals(msgContent)){
			
			boolean b = new SendMsg().sendMessage(telNo.trim().split(","), msgContent);
			if(b)
				out.println("{success:"+"'发送成功'"+"}");
			else
				out.println("{failure:"+"'发送失败，请重试'"+"}");				
		}	
		out.flush();
		return null;
	}
}
